```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据库锁机制：行锁与表锁详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::before {
            content: '';
            position: absolute;
            z-index: -1;
            top: 0;
            bottom: 0;
            left: -0.25em;
            right: -0.25em;
            background-color: rgba(102, 126, 234, 0.2);
            transform: skewX(-15deg);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-bottom: 1rem;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5em;
            line-height: 0.7;
            padding: 0.1em 0.1em 0 0;
            color: #667eea;
            font-weight: bold;
        }
        .divider {
            position: relative;
            height: 1px;
            background: linear-gradient(to right, transparent, rgba(0,0,0,0.1), transparent);
        }
        .divider::after {
            content: '';
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 40px;
            height: 3px;
            background: #667eea;
            border-radius: 3px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">数据库锁机制</h1>
                    <h2 class="text-2xl md:text-3xl font-semibold mb-6">行锁与表锁的现代解析</h2>
                    <p class="text-lg opacity-90 mb-8">在并发数据库环境中，锁机制是确保数据一致性和完整性的关键。了解行锁与表锁的特性和应用场景，是构建高性能数据库系统的基石。</p>
                    <div class="flex space-x-4">
                        <div class="flex items-center">
                            <i class="fas fa-database text-xl mr-2"></i>
                            <span>并发控制</span>
                        </div>
                        <div class="flex items-center">
                            <i class="fas fa-lock text-xl mr-2"></i>
                            <span>数据一致性</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white bg-opacity-10 p-6 rounded-xl backdrop-blur-sm border border-white border-opacity-20">
                        <div class="mermaid">
                            graph LR
                            A[数据库锁机制] --> B[行锁]
                            A --> C[表锁]
                            B --> D[高并发性能]
                            B --> E[细粒度控制]
                            B --> F[可能导致死锁]
                            C --> G[实现简单]
                            C --> H[低并发性能]
                            C --> I[全表锁定]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <p class="text-lg text-gray-600 mb-8 drop-cap">数据库的行锁和表锁是用于控制并发访问数据库的两种基本锁机制。它们分别对不同级别的数据进行锁定，从而实现数据的一致性和避免冲突。在现代数据库系统中，理解这两种锁机制的差异和应用场景对于设计和优化系统性能至关重要。</p>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl p-6 card">
                    <div class="feature-icon bg-indigo-100 text-indigo-600">
                        <i class="fas fa-align-left text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-indigo-700">行锁 (Row-Level Lock)</h3>
                    <p class="text-gray-600">对数据库表中的某一行数据进行锁定，允许多个事务同时对不同行进行操作，提高并发性能。</p>
                </div>
                <div class="bg-white rounded-xl p-6 card">
                    <div class="feature-icon bg-purple-100 text-purple-600">
                        <i class="fas fa-table text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-purple-700">表锁 (Table-Level Lock)</h3>
                    <p class="text-gray-600">对整个数据库表进行锁定，实现简单但会限制并发访问，适用于低并发或批量操作场景。</p>
                </div>
            </div>
        </section>

        <!-- Row Lock Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mr-4">行锁详解</h2>
                <span class="px-4 py-1 bg-indigo-100 text-indigo-800 rounded-full text-sm font-medium">高并发首选</span>
            </div>
            
            <div class="bg-white rounded-xl overflow-hidden shadow-sm mb-8">
                <div class="p-6 md:p-8">
                    <p class="text-gray-600 mb-6">行锁是指对数据库表中的某一行数据进行锁定。只有当事务对特定行进行操作时，才会对该行加锁。这种精细化的锁定机制是现代数据库系统的核心特性之一。</p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-bold text-lg mb-3 text-indigo-700 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>
                                主要特点
                            </h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>锁粒度小，仅锁定特定行</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>允许多事务并行访问不同行</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span>可能导致锁竞争和死锁</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-bold text-lg mb-3 text-indigo-700 flex items-center">
                                <i class="fas fa-balance-scale mr-2"></i>
                                优缺点分析
                            </h4>
                            <div class="mb-4">
                                <span class="inline-block bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full font-medium mr-2">优点</span>
                                <span class="text-gray-600">提高并发能力，减少锁范围</span>
                            </div>
                            <div>
                                <span class="inline-block bg-red-100 text-red-800 text-xs px-2 py-1 rounded-full font-medium mr-2">缺点</span>
                                <span class="text-gray-600">管理复杂，可能引发死锁</span>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-indigo-50 rounded-lg p-4 border border-indigo-100">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <i class="fas fa-lightbulb text-indigo-500 text-xl"></i>
                            </div>
                            <div class="ml-3">
                                <h4 class="font-bold text-indigo-800">应用场景</h4>
                                <p class="text-indigo-600">行锁非常适合需要高并发读取和写入操作的场景，例如电商平台的订单处理系统。它也是处理大型数据表时的理想选择，因为可以避免全表锁定的性能开销。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Visualization -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h4 class="font-bold text-lg mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-chart-bar mr-2 text-indigo-600"></i>
                        行锁机制示意图
                    </h4>
                    <div class="mermaid">
                        flowchart LR
                        T1[事务A] -->|锁定行1| R1[行1]
                        T2[事务B] -->|锁定行2| R2[行2]
                        T3[事务C] -->|等待行1释放| R1
                    </div>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h4 class="font-bold text-lg mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-random mr-2 text-indigo-600"></i>
                        并发性能对比
                    </h4>
                    <div class="mermaid">
                        barChart
                        title 锁类型与并发能力
                        x-axis 锁类型
                        y-axis 并发性能
                        series 事务数量
                        "行锁": 8
                        "表锁": 2
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Divider -->
        <div class="divider my-12"></div>
        
        <!-- Table Lock Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mr-4">表锁详解</h2>
                <span class="px-4 py-1 bg-purple-100 text-purple-800 rounded-full text-sm font-medium">简单可靠</span>
            </div>
            
            <div class="bg-white rounded-xl overflow-hidden shadow-sm mb-8">
                <div class="p-6 md:p-8">
                    <p class="text-gray-600 mb-6">表锁是指对整个数据库表进行锁定。当一个事务对表进行操作时，表中的所有数据行都会被锁定。这种锁定机制虽然简单，但在某些场景下仍然非常有用。</p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-bold text-lg mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>
                                主要特点
                            </h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>锁粒度大，锁定整个表</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>实现和管理简单</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-1 mr-2"></i>
                                    <span>限制并发访问</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-bold text-lg mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-balance-scale mr-2"></i>
                                优缺点分析
                            </h4>
                            <div class="mb-4">
                                <span class="inline-block bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full font-medium mr-2">优点</span>
                                <span class="text-gray-600">实现简单，管理开销小</span>
                            </div>
                            <div>
                                <span class="inline-block bg-red-100 text-red-800 text-xs px-2 py-1 rounded-full font-medium mr-2">缺点</span>
                                <span class="text-gray-600">限制并发，可能造成性能瓶颈</span>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-purple-50 rounded-lg p-4 border border-purple-100">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <i class="fas fa-lightbulb text-purple-500 text-xl"></i>
                            </div>
                            <div class="ml-3">
                                <h4 class="font-bold text-purple-800">应用场景</h4>
                                <p class="text-purple-600">表锁适用于低并发环境或需要对整个表进行操作的场景，如批量数据更新或维护操作。当事务需要操作表中的多个数据行时，表锁可以确保数据的一致性和完整性。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Visualization -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h4 class="font-bold text-lg mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-chart-bar mr-2 text-purple-600"></i>
                        表锁机制示意图
                    </h4>
                    <div class="mermaid">
                        flowchart LR
                        T1[事务A] -->|锁定整个表| Table[数据表]
                        T2[事务B] -->|等待表释放| Table
                        T3[事务C] -->|等待表释放| Table
                    </div>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h4 class="font-bold text-lg mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-stopwatch mr-2 text-purple-600"></i>
                        响应时间对比
                    </h4>
                    <div class="mermaid">
                        barChart
                        title 锁类型与响应时间
                        x-axis 锁类型
                        y-axis 时间(ms)
                        series 平均响应时间
                        "行锁": 120
                        "表锁": 350
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Comparison Section -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold text-gray-800 mb-8">行锁 vs 表锁：关键对比</h2>
            
            <div class="bg-white rounded-xl overflow-hidden shadow-sm">
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">对比项</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-indigo-500 uppercase tracking-wider">行锁</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-purple-500 uppercase tracking-wider">表锁</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">锁粒度</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">单行数据</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">整个数据表</td>
                            </tr>
                            <tr class="bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">并发性能</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高 (允许多事务并行)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低 (限制并发访问)</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">实现复杂度</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">复杂 (需要管理多个锁)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">简单 (单一锁管理)</td>
                            </tr>
                            <tr class="bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">死锁风险</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">较高 (多锁交互)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低 (单一锁)</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">典型应用</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">电商订单系统、高并发应用</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">数据迁移、批量处理</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
        
        <!-- Summary Section -->
        <section class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-xl p-8 md:p-10 mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-6">总结与选择建议</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700">行锁适用情况</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                            <span>需要高并发访问和操作的数据场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                            <span>系统能够处理锁竞争和死锁问题</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                            <span>事务通常只操作少量数据行</span>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-purple-700">表锁适用情况</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                            <span>低并发或简单操作的场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                            <span>需要对整个表进行批量操作</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mr-2 mt-1"></i>
                            <span>系统资源有限，需要简单实现</span>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="mt-8 p-4 bg-white rounded-lg shadow-xs">
                <div class="flex items-start">
                    <div class="flex-shrink-0">
                        <i class="fas fa-exclamation-circle text-yellow-500 text-xl"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-gray-700"><span class="font-semibold">专业建议：</span>现代数据库系统通常支持多粒度锁定机制，允许开发者在不同场景下选择合适的锁类型。在某些情况下，数据库优化器会自动选择最佳锁定策略。理解这些机制有助于编写更高效的SQL语句和设计更好的数据库架构。</p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#E2E8F0',
                primaryTextColor: '#4A5568',
                primaryBorderColor: '#CBD5E0',
                lineColor: '#A0AEC0',
                secondaryColor: '#F7FAFC',
                tertiaryColor: '#EDF2F7'
            }
        });
        
        // 微交互效果
        document.querySelectorAll('.mermaid').forEach(el => {
            el.addEventListener('click', function() {
                this.classList.toggle('bg-gray-50');
            });
        });
    </script>
</body>
</html>
```